package com.p2p.front.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.p2p.base.page.PageVo;
import com.p2p.front.dal.dao.UserDao;
import com.p2p.front.dal.dao.UserLoanDao;
import com.p2p.front.service.UserLoanService;

/**
 * leiwen@yiqihao.com
 */
@Service
public class UserLoanServiceImpl implements UserLoanService {

	@Resource
	private UserLoanDao userLoanDao;

	public PageVo myLoanList(PageVo vo) {
		List list = userLoanDao.myLoanList(vo);
		vo.setList(list);
		return vo;
	}

	public Map<String, Object> count(Integer uid) {
		Map<String,Object> map = new HashMap<String,Object>();
		int userExistInp2ploaninfo = userLoanDao.userExistInp2ploaninfo(uid);
		int userExistInp2ploanrepay = userLoanDao.userExistInp2ploanrepay(uid);
		double total_borrow = 0.0;
		int  succeed_time = 0;
		double back_benxi = 0.0;
		int normal_backed_time = 0;
		double to_back_benxi = 0.0;
		int going_back_time = 0;
		double to_back_manage_fee = 0.0;
		int plat_back_time = 0;
		if(userExistInp2ploaninfo!=0) {
			total_borrow = userLoanDao.getTotoalBorrow(uid)*1.0/100;		//总结款金额
			succeed_time = userLoanDao.getSucceedTime(uid);			        //成功借款次数
		} 
		if(userExistInp2ploanrepay!=0) {
			if(userLoanDao.getBackBenxi(uid)!=null) {				//已还本息
				back_benxi = userLoanDao.getBackBenxi(uid)*1.0/100;
			}
			if(userLoanDao.getNormalBackTime(uid)!=null) { 			//正常还清笔数
				normal_backed_time = userLoanDao.getNormalBackTime(uid);
			}
			to_back_benxi = userLoanDao.getToBackBenxi(uid)*1.0/100;		//待还本息
			going_back_time = userLoanDao.getGoingBackTime(uid);		//正在还款笔数
			to_back_manage_fee = userLoanDao.getTobackManagefee(uid)*1.0/100;//待还管理费
			plat_back_time = userLoanDao.getPlatBackTime(uid);		//平台代还笔数
		}
		map.put("total_borrow", total_borrow);
		map.put("back_benxi", back_benxi);
		map.put("to_back_benxi", to_back_benxi);
		map.put("to_back_manage_fee", to_back_manage_fee);
		map.put("succeed_time", succeed_time);
		map.put("normal_backed_time", normal_backed_time);
		map.put("going_back_time", going_back_time);
		map.put("plat_back_time", plat_back_time);
		return map;
	}

}
